<?php
require_once ( PATH_DATABASE.'class.dbcontrol.inc.php' );
class Db_UserAccount extends db {
	public function __construct(){
//		$this->setTable('ams_packet');
	}
	public function doInsertUserAccount($aData){
		parent::StartTrans();
                parent::insert( 'ams_user_account', Array(
        						'user_id' => $aData[user_id],
						        'can_be_downloaded_items' =>$aData[can_be_downloaded_items],
						        'downloaded_items' =>$aData[downloaded_items],
        						'start_date' =>$aData[start_date],
        						'end_date'=>$aData[end_date],
                  ), false,__LINE__, __FILE__ );
                $id = parent::get_last_insert_id();
                parent::Commit();
                return $id;
	}
	public function doListUserAccount(){
		$sSql = "SELECT U.*, A.admin_fullname FROM ams_user_account as U
					INNER JOIN ams_admin as A
					ON U.user_id = A.admin_id";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
	public function doDeleteUserAccountById($id){
		$sSql = "DELETE FROM `ams_user_account` WHERE `id` = '$id'"; 			 
		parent::execute_query($sSql, __LINE__, __FILE__);
		return true;
	}
	public function doUpdateUserAccountById($aData, $id){
		parent::StartTrans();     
                parent::update( 'ams_user_account', Array(
        						'user_id' => $aData[user_id],
						        'can_be_downloaded_items' =>$aData[can_be_downloaded_items],
						        'downloaded_items' =>$aData[downloaded_items],
        						'start_date' =>$aData[start_date],
        						'end_date'=>$aData[end_date],
                      ),Array('id' => $id),__LINE__,__FILE__);
		parent::Commit();
		return true;
	}
	public function doGetUserAccountById($id){
		$sSql = "SELECT U.*, A.admin_fullname FROM ams_user_account as U
					INNER JOIN ams_admin as A
					ON U.user_id = A.admin_id WHERE U.id='$id' AND A.admin_role='3'";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
    public function doListUserAccountActive(){
		$sSql = "SELECT * FROM ams_packet WHERE status = 1";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
    public function doInsertTrans($aData){
		parent::StartTrans();
                parent::insert( 'ams_transactions', $aData, false,__LINE__, __FILE__ );
                $id = parent::get_last_insert_id();
                parent::Commit();
                return $id;
	}
	public function doGetUser(){
		$sSql = "SELECT * FROM ams_admin 
					WHERE admin_id NOT IN (SELECT user_id FROM ams_user_account) AND admin_role='3'";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
}